#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/8/16 20:29
# @USER    : Shengji He
# @File    : RemoveDuplicatesSortedList.py
# @Software: PyCharm
# @Version  : Python-
# @TASK:


# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        """
        Given a sorted linked list, delete all duplicates such that each element appear only once.

        Example 1:

            Input: 1->1->2
            Output: 1->2
        Example 2:

            Input: 1->1->2->3->3
            Output: 1->2->3

        :param head:
        :return:
        """
        ans = head
        temp = ans
        while temp and temp.next:
            if temp.val == temp.next.val:
                temp.next = temp.next.next
            else:
                temp = temp.next

        return ans


if __name__ == '__main__':
    print('done')
